Move initDomain out of image.py and into XendDomainInfo. The only thing that
authoremellor@ewan <emellor@ewan>
Thu, 22 Sep 2005 16:52:07 +0000 (17:52 +0100)
committeremellor@ewan <emellor@ewan>
Thu, 22 Sep 2005 16:52:07 +0000 (17:52 +0100)
needed any of the state of image.py was the bootloader code, which says there,
but all the rest was doing something that belonged more properly in
XendDomainInfo, with all the other generic domain initialisation code.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/image.py

index 5dab516d8082c456e778754dd53fbc8eb0fdd06c..8e5cc00638816937bc4f98aaf547b9a79368e292 100644 (file)
@@ -706,32 +706,14 @@ class XendDomainInfo:
         """
         # todo - add support for scheduling params?
         try:
-            # Initial domain create.
             if 'image' not in self.info:
                 raise VmError('Missing image in configuration')
 
-            self.image = ImageHandler.create(self, self.info['image'],
+            self.image = ImageHandler.create(self,
+                                             self.info['image'],
                                              self.info['device'])
 
-            log.debug('XendDomainInfo.construct: '
-                      'calling initDomain(%s %s %s %s %s)',
-                      str(self.domid),
-                      str(self.info['memory_KiB']),
-                      str(self.info['ssidref']),
-                      str(self.info['cpu']),
-                      str(self.info['cpu_weight']))
-
-            self.setDomid(self.image.initDomain(self.domid,
-                                                self.info['memory_KiB'],
-                                                self.info['ssidref'],
-                                                self.info['cpu'],
-                                                self.info['cpu_weight'],
-                                                self.info['bootloader']))
-            
-            self.info['start_time'] = time.time()
-
-            log.debug('init_domain> Created domain=%d name=%s memory=%d',
-                      self.domid, self.info['name'], self.info['memory_KiB'])
+            self.initDomain()
 
             # Create domain devices.
             self.construct_image()
@@ -745,6 +727,38 @@ class XendDomainInfo:
             self.destroy()
             raise
 
+
+    def initDomain(self):
+        log.debug('XendDomainInfo.initDomain: %s %s %s %s)',
+                  str(self.domid),
+                  str(self.info['memory_KiB']),
+                  str(self.info['ssidref']),
+                  str(self.info['cpu_weight']))
+
+        self.domid = xc.domain_create(dom = self.domid or 0,
+                                      ssidref = self.info['ssidref'])
+        if self.domid <= 0:
+            raise VmError('Creating domain failed: name=%s' %
+                          self.vm.getName())
+
+        if self.info['bootloader']:
+            self.image.handleBootloading()
+
+        xc.domain_setcpuweight(self.domid, self.info['cpu_weight'])
+        m = self.image.getDomainMemory(self.info['memory_KiB'])
+        xc.domain_setmaxmem(self.domid, m)
+        xc.domain_memory_increase_reservation(self.domid, m, 0, 0)
+
+        cpu = self.info['cpu']
+        if cpu is not None and cpu != -1:
+            xc.domain_pincpu(self.domid, 0, 1 << cpu)
+
+        self.info['start_time'] = time.time()
+
+        log.debug('init_domain> Created domain=%d name=%s memory=%d',
+                  self.domid, self.info['name'], self.info['memory_KiB'])
+
+
     def configure_vcpus(self, vcpus):
         d = {}
         for v in range(0, vcpus):
index dfea90882745c1357133e00a604915e9fe8281f3..1db481ecac402502fbb8bfda99603711138fd583 100644 (file)
@@ -36,9 +36,6 @@ MAX_GUEST_CMDLINE = 1024
 class ImageHandler:
     """Abstract base class for image handlers.
 
-    initDomain() is called to initialise the domain memory and parse
-    the configuration.
-    
     createImage() is called to configure and build the domain from its
     kernel image and ramdisk etc.
 
@@ -132,6 +129,12 @@ class ImageHandler:
                         ("image/cmdline", self.cmdline),
                         ("image/ramdisk", self.ramdisk))
 
+
+    def handleBootloading():
+        self.unlink(self.kernel)
+        self.unlink(self.ramdisk)
+
+
     def unlink(self, f):
         if not f: return
         try:
@@ -139,37 +142,6 @@ class ImageHandler:
         except OSError, ex:
             log.warning("error removing bootloader file '%s': %s", f, ex)
 
-    def initDomain(self, dom, memory, ssidref, cpu, cpu_weight, bootloading):
-        """Initial domain create.
-
-        @param memory In KiB
-        @return domain id
-        """
-
-        mem_kb = self.getDomainMemory(memory)
-        dom = xc.domain_create(dom = dom or 0, ssidref = ssidref)
-        # if bootloader, unlink here. But should go after buildDomain() ?
-        if bootloading:
-            self.unlink(self.kernel)
-            self.unlink(self.ramdisk)
-        if dom <= 0:
-            raise VmError('Creating domain failed: name=%s' %
-                          self.vm.getName())
-        if cpu is None:
-            cpu = -1;
-        log.debug("initDomain: cpu=%d mem_kb=%d ssidref=%d dom=%d", cpu, mem_kb, ssidref, dom)
-        xc.domain_setcpuweight(dom, cpu_weight)
-        xc.domain_setmaxmem(dom, mem_kb)
-
-        try:
-            xc.domain_memory_increase_reservation(dom, mem_kb, 0, 0)
-        except:
-            xc.domain_destroy(dom)
-            raise
-
-        if cpu != -1:
-            xc.domain_pincpu(dom, 0, 1<<int(cpu))
-        return dom
 
     def createImage(self):
         """Entry point to create domain memory image.